﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Graphics;
using OpenTK.Platform;
using OpenTK;
using System.Diagnostics;

namespace Clandestine.Graphics
{
	static class GraphicsContextExtensions
	{
		public static void SetupAuto(this GraphicsContext context, NativeWindow window)
		{
			Debug.Assert(GraphicsContext.ShareContexts, "Clandestine.Graphics requires GraphicsContext.ShareContexts to be true prior to the creation of any GraphicsContexts!");
			context.MakeCurrent(window.WindowInfo);
			context.ErrorChecking = true; // ErrorChecking is forcibly disabled in Release OpenTK builds anyway.
			context.VSync = true;
			(context as IGraphicsContextInternal).LoadAll();
			window.Resize += new EventHandler<EventArgs>((o, ea) => context.Update(window.WindowInfo));
			context.MakeCurrent(null);
		}
	}

	static class Color4Extensions
	{
		// why no Color4 multiply operator?!
		public static Color4 Multiply(this Color4 one, Color4 two)
		{
			one.R *= two.R;
			one.G *= two.G;
			one.B *= two.B;
			one.A *= two.A;
			return one;
		}
	}
}
